package view;

import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.SwingConstants;
import javax.swing.ImageIcon;
import java.awt.Point;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JTextField;
import javax.swing.JTable;

import common.loadData;

public class addCriminalType extends JFrame {
	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JButton btnClose = null;
	private JButton btnAdd = null;
	private JPanel jPanel = null;
	private JLabel lbComplaint = null;
	private JLabel icon = null;
	private JLabel lbName = null;
	private JTextField txtTypeCrime = null;
	private JTable TableCrimetype = null;
	
	public addCriminalType() {
		super();
		initialize();
	}

	private void initialize() {
		this.setSize(504, 378);
		this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/image/management.png")));
		this.setResizable(false);
		this.setName("addCriminalType");
		this.setContentPane(getJContentPane());
		this.setTitle("Criminal Type");
	}

	private JPanel getJContentPane() {
		if (jContentPane == null) {
			lbName = new JLabel();
			lbName.setText("New Type:");
			lbName.setLocation(new Point(96, 65));
			lbName.setSize(new Dimension(97, 30));
			lbName.setFont(new Font("Dialog", Font.BOLD, 14));
			icon = new JLabel();
			icon.setText("");
			icon.setLocation(new Point(7, 6));
			icon.setSize(new Dimension(77, 77));
			icon.setIcon(new ImageIcon(getClass().getResource("/image/crime.png")));
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getBtnClose(), null);
			jContentPane.add(getBtnAdd(), null);
			jContentPane.add(getJPanel(), null);
			jContentPane.add(icon, null);
			jContentPane.add(lbName, null);
			jContentPane.add(getTxtTypeCrime(), null);
			jContentPane.add(getTableCrimetype(), null);
		}
		return jContentPane;
	}

	private JButton getBtnClose() {
		if (btnClose == null) {
			btnClose = new JButton();
			btnClose.setHorizontalTextPosition(SwingConstants.RIGHT);
			btnClose.setIcon(new ImageIcon(getClass().getResource("/image/Close.png")));
			btnClose.setText("Close");
			btnClose.setLocation(new Point(377, 304));
			btnClose.setSize(new Dimension(99, 28));
			btnClose.setHorizontalAlignment(SwingConstants.LEFT);
			btnClose.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					loadData.tab=2;
					mainForm a = new mainForm();
					a.setVisible(true);	
					dispose();
					
				}
			});
		}
		return btnClose;
	}

	private JButton getBtnAdd() {
		if (btnAdd == null) {
			btnAdd = new JButton();
			btnAdd.setHorizontalTextPosition(SwingConstants.RIGHT);
			btnAdd.setIcon(new ImageIcon(getClass().getResource("/image/OK.png")));
			btnAdd.setText("Add");
			btnAdd.setLocation(new Point(383, 65));
			btnAdd.setSize(new Dimension(92, 28));
			btnAdd.setHorizontalAlignment(SwingConstants.LEFT);
		}
		return btnAdd;
	}

	private JPanel getJPanel() {
		if (jPanel == null) {
			lbComplaint = new JLabel();
			lbComplaint.setForeground(new Color(8, 66, 36));
			lbComplaint.setText("Criminal Type");
			lbComplaint.setSize(new Dimension(124, 28));
			lbComplaint.setLocation(new Point(0, 0));
			lbComplaint.setFont(new Font("Dialog", Font.BOLD, 18));
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, Color.red));
			jPanel.setLocation(new Point(148, 18));
			jPanel.setSize(new Dimension(125, 26));
			jPanel.add(lbComplaint, null);
		}
		return jPanel;
	}

	private JTextField getTxtTypeCrime() {
		if (txtTypeCrime == null) {
			txtTypeCrime = new JTextField();
			txtTypeCrime.setLocation(new Point(202, 65));
			txtTypeCrime.setSize(new Dimension(159, 28));
		}
		return txtTypeCrime;
	}

	private JTable getTableCrimetype() {
		if (TableCrimetype == null) {
			String[] columnNames = {
					"No",
					"Name",
					"Last update"
					}; 
			Object[][] data = {
					{"1", "dua xe","27/08/2011"},
					{"2", "giet nguoi","17/09/2011"},
					{"3", "cuop cua","13/03/2011"}
					}; 
			TableCrimetype = new JTable(data,columnNames);
			TableCrimetype.setBounds(new Rectangle(31, 105, 445, 173));
		}
		return TableCrimetype;
	}

}
